﻿<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top:0px;padding-bottom:0px;" lay-filter="SearchForm">
		<div class="layui-form-item">
			<div class="layui-inline" style="margin-right: 0;">
				<div class="layui-input-inline">
					<select id="dropSearchName">
						<option value="UserName" selected="selected">会员名</option>
						<option value="ClientID">客户名称</option>
						<option value="Bank">银行名称</option>
						<option value="OrderID">跟单员</option>
					</select>
				</div>
				<div class="layui-input-inline" style="margin: 0px;">
					<input type="text" class="layui-input" id="txtSearchKeyword" name="txtSearchKeyword" placeholder="请输入搜索关键字" autocomplete="off" onkeypress="javascript:return DefaultButton(event, 'btnSearch')">
				</div>
				<div class="layui-input-inline" style="margin: 0px;width: 350px;">
					<label class="layui-form-label">交易日期</label>
					<div class="layui-input-inline" style="width: 100px;">
						<input type="text" class="layui-input date-item" id="ctlBeginDate" placeholder="yyyy-MM-dd" autocomplete="off" readonly="readonly" />
					</div>
					<div class="layui-input-inline" style="width: 100px;">
						<input type="text" class="layui-input date-item" id="ctlEndDate" placeholder="yyyy-MM-dd" autocomplete="off" readonly="readonly" />
					</div>
				</div>
				<div class="layui-input-inline" style="margin: 0px;">
					<select id="dropStatus">
						<option value="-1" selected="selected">资金状态</option>
						<option value="0">未确认</option>
						<option value="1">已确认</option>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<button id="btnSearch" type="button" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnSearch">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
			</div>
		</div>
	</div>

	<div class="layui-card-body">
		<div class="layui-tab layui-tab-brief" lay-filter="tabList">
			<ul class="layui-tab-title">
				<li lay-id="0" class="layui-this">全部</li>
				<li lay-id="1">收入</li>
				<li lay-id="2">支出</li>
			</ul>
			<div class="layui-tab-content">
				<table id="tblList" lay-filter="tblList"></table>
			</div>
			<div class="layui-elem-quote">注意：没确认的资金将不会计入合计当中。</div>
		</div>
		<input type="hidden" id="hidTab" value="0" />
		<script type="text/html" id="toolbarHead">
			<div class="layui-form-item" style="margin: auto;">
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnDeleteMulti">批量删除</button>
					<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnBatchPass">批量确认</button>
					<span style="height: 30px;">
						总收入：<span id="totalIncome" style="font-weight: bold; margin-right: 10px;">0</span>
						总支出：<span id="totalPayout" style="font-weight: bold; margin-right: 10px;">0</span>
						总余额：<span id="totalBalance" style="font-weight: bold; margin-right: 10px;">0</span>
					</span>
				</div>
			</div>
		</script>
		<script type="text/html" id="tblBarCol">
			<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-search"></i>查看</a>
			{{#  if(d.Status != 1){ }}
			<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="pass"><i class="layui-icon layui-icon-edit"></i>确认</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			{{#  } }}
		</script>
	</div>
</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		layui.use(['form', 'table', 'element', 'laydate'], function () {
			var table = layui.table;
			var form = layui.form;
			var element = layui.element;
			var laydate = layui.laydate;

			lay('.date-item').each(function () {
				laydate.render({
					elem: this
				});
			});

			//获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
			var layid = location.hash.replace(/^#tabList=/, '');
			if (layid != null && layid != "") {
				element.tabChange('tabList', layid);
				$("#hidTab").val(layid);
			}
			//监听Tab切换，以改变地址hash值
			element.on('tab(tabList)', function () {
				location.href = location.pathname + "#tabList=" + this.getAttribute('lay-id');
				window.location.reload();
			});

			var myCols = [
				{ type: "checkbox", width: 30, align: 'center' },
				{ field: 'DateAndTime', width: 170, title: '交易时间', align: 'center', templet: function (d) { return showDateTime(d.DateAndTime); } },
				{ field: 'UserName', minWidth: 100, maxWidth: 200, title: '会员名', align: 'center' },
				{ field: 'ClientName', minWidth: 100, maxWidth: 200, title: '客户名', align: 'center' },
				{ field: 'Money', width: 100, title: '交易金额', align: 'center', totalRow: true, templet: function (d) { return GetUserMoneyHtml(d.Money); } },
				{ field: 'MoneyType', width: 100, title: '交易方式', align: 'center', templet: function (d) { return GetUserMoneyTypeText(d.MoneyType); } },
				{ field: 'Bank', width: 100, title: '银行名称', align: 'center' },
				{ field: 'Functionary', width: 100, title: '跟单员', align: 'center' },
				{ field: 'Remark', minWidth: 200, title: '备注', align: 'left' },
				{ field: 'Status', width: 50, title: '确认', align: 'center', templet: function (d) { return GetUserMoneyStatusHtml(d.Status); } },
				{ field: 'ItemID', minWidth: 150, maxWidth: 250, title: '操作', align: "center", templet: '#tblBarCol' }
			];
			
			//加载表格
			table.render({
				elem: '#tblList'
				, url: '/Admin/Finance/GetBankrollItemList'
				, toolbar: '#toolbarHead'
				, where: GetSearchParam()
				, totalRow: true
				, request: {
					pageName: 'PageNum' //页码的参数名称，默认：page
					, limitName: 'PageSize' //每页数据量的参数名，默认：limit
				}
				, cols: [myCols]
				, parseData: function (res) { //res 即为原始返回的数据
					return {
						"code": 0, //解析接口状态
						"msg": "", //解析提示文本
						"count": res.RecordTotal, //解析数据长度
						"data": res.RowList, //解析数据列表
						"TotalIncome": res.TotalIncome,
						"TotalPayout": res.TotalPayout
					};
				}
				, limits: [10, 15, 20, 25, 50, 100]
				, limit: 15
				, page: true
				, done: function (res, curr, count) {
					$("#totalIncome").text('¥' + res.TotalIncome);
					$("#totalPayout").text('¥' + res.TotalPayout);
					$("#totalBalance").text('¥' + (parseFloat(res.TotalIncome) + parseFloat(res.TotalPayout)).toFixed(2));
				}
			});
			//监听表格操作列
			table.on('tool(tblList)', function (obj) {
				if (obj.event === 'view') {
					layer_show('查看资金记录', '/Admin/Finance/ViewBankrollItem?id=' + obj.data.ItemID);
					return false;
				} else if (obj.event === 'del') {
					DeleteSingle(obj.data.ItemID, "/Admin/Finance/DelBankroll");
					return false;
				} else if (obj.event === 'pass') {
					var param = { "ids": obj.data.ItemID, "MoneyStatus": 1 };
					UpdateMulti('/Admin/Finance/UpdateBankrollStatus', param);
					return false;
				}
			});
			//监听搜索操作
			form.on('submit(btnSearch)', function (data) {
				reloadTable();
				return false;
			});
			//监听批量删除
			form.on('submit(btnDeleteMulti)', function (data) {
				var ids = GetSelectIds();
				DeleteMulti(ids, '/Admin/Finance/DelBankrollMulti');
				return false;
			});
			//监听批量确认
			form.on('submit(btnBatchPass)', function (data) {
				var ids = GetSelectIds();
				var param = { "ids": ids, "MoneyStatus": 1 };
				UpdateMulti('/Admin/Finance/UpdateBankrollStatus', param);
				return false;
			});
			//表格重载
			function reloadTable(tableID = 'tblList') {
				table.reload(tableID, {
					page: {
						curr: 1
					}
					, where: GetSearchParam()
				}, 'data');
			};
			function GetSearchParam() {
				var SearchName = $("#dropSearchName").val();
				var SearchKeyword = $("#txtSearchKeyword").val();
				var TabStatus = $("#hidTab").val();
				var BeginDate = $("#ctlBeginDate").val();
				var EndDate = $("#ctlEndDate").val();
				var Status = $("#dropStatus").val();
				var objParam = { "SearchName": SearchName, "SearchKeyword": SearchKeyword, "TabStatus": TabStatus, "BeginDate": BeginDate, "EndDate": EndDate, "Status": Status};
				return objParam;
			}
			function GetSelectIds() {
				var checkStatus = table.checkStatus('tblList');
				var data = checkStatus.data;
				var ids = "";
				for (j = 0, len = data.length; j < len; j++) {
					if (j < len - 1) {
						ids += data[j].ItemID + ',';
					} else {
						ids += data[j].ItemID;
					}
				}
				return ids;
			}
		});
	</script>
}